import { getProfileAPI } from '@/api/user'
import { routes } from '@/router/index'
import { resetRouter } from '@/router/index'

export default {
    namespaced: true,
    state: {
        permission: [],  //权限标识
        menuList: [],  //路由规则
    },
    mutations: {
        // 修改权限标识
        setPermission(state, newPermission) {
            state.permission = newPermission;
        },
        // 修改权限规则
        setMenuList(state, asyncRoutes) {
            state.menuList = [...routes, ...asyncRoutes]
        },
        // 清空路由规则
        clearMenuList(state) {
            state.menuList = [];
            resetRouter();
        }
    },
    getters: {},
    actions: {
        async getUserPermission(store) {
            const res = await getProfileAPI()
            store.commit('setPermission', res.data.permissions)
            return res.data.permissions
        }
    },
}